package com.yonyou.brigade.third_parties.didi.controller;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.basic_init.service.IUserCenterService;
import com.yonyou.brigade.third_parties.didi.model.third.InvoiceApplyParam;
import com.yonyou.brigade.third_parties.didi.model.third.InvoiceQueryParam;
import com.yonyou.brigade.third_parties.didi.model.third.InvoiceTitle;
import com.yonyou.brigade.third_parties.didi.model.third.InvoiceType;
import com.yonyou.brigade.third_parties.didi.service.IDiDiInvoiceService;
import com.yonyou.ybzboot.uc.dto.UcUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 发票操作 controller
 *
 * @author kangfw5
 */
@RestController
@RequestMapping("/third/didi/invoice")
public class DiDiInvoiceController {

    @Autowired
    private IDiDiInvoiceService diDiInvoiceService;

    @Autowired
    private IUserCenterService userCenterService;

    /**
     * 获取发票抬头
     *
     * @param tenantId    租户ID
     * @param orgPk       组织PK
     * @param invoiceType 发票类型
     */
    @RequestMapping(value = "/getTitleList", method = RequestMethod.GET)
    public List<InvoiceTitle> getTitleList(String tenantId, String orgPk, InvoiceType invoiceType) {
        return diDiInvoiceService.getTitleList(tenantId, orgPk, invoiceType);
    }

    /**
     * 申请开票
     *
     * @param tenantId          租户ID
     * @param invoiceApplyParam 开票信息
     * @return 发票ID
     */
    @RequestMapping(value = "/apply", method = RequestMethod.POST)
    public String applyInvoice(@RequestParam(name = "tenantId") String tenantId, @RequestParam(name = "phone") String phone, @RequestBody InvoiceApplyParam invoiceApplyParam) {
        UcUserDto ucUserDto = userCenterService.getCompleteUcUserDtoByPhone(phone, tenantId);
        return diDiInvoiceService.applyForInvoice(tenantId, null, ucUserDto.getUserId(), invoiceApplyParam);
    }

    /**
     * 查询开票信息
     *
     * @param tenantId          租户ID
     * @param invoiceQueryParam 发票查询参数
     */
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public JSONObject queryInvoice(@RequestParam String tenantId, @RequestBody InvoiceQueryParam invoiceQueryParam) {
        return diDiInvoiceService.queryInvoice(tenantId, null, invoiceQueryParam);
    }

    /**
     * 下载滴滴电子发票\行程单到阿里云
     *
     * @param tenantId  租户ID
     * @param invoiceId 发票ID
     * @return
     */
    @RequestMapping(value = "/download", method = RequestMethod.GET)
    public List downloadInvoice(@RequestParam String tenantId, String invoiceId) {
        return diDiInvoiceService.downloadInvoice(tenantId, invoiceId);
    }
}
